<!--
@Description:物流核心指标详情
@Author:zqy
@Date:2021-09-03 13:05:27
@Last Modified by:zqy
@Last Modified time:2021-09-03 13:05:27
-->
<template>
  <div class="dlg-page">
    <div class="dlg-title">
      {{ detailData.title }}
    </div>
    <div class="dlg-tab">
      <div
        v-for="(item,index) in tabDisName"
        :key="index"
        class="tab-item"
        :class="{'active':tabIndex===index}"
        @click="tabIndex=index"
      >{{ item }}配送中心</div>
    </div>
    <div class="core-detail-list">
      <div class="tr">
        <div class="th">今日</div>
        <div class="th">昨日</div>
        <div class="th">本月</div>
        <div class="th">{{ detailData.lastColName }}</div>
      </div>
      <template>
        <div v-for="(item,index) in dataList" :key="index" class="tr">
          <div class="td">{{ item[detailData.today] | filterForamtThousand }}</div>
          <div class="td">{{ item[detailData.yesterday] | filterForamtThousand }}</div>
          <div class="td">{{ item[detailData.month] | filterForamtThousand }}</div>
          <div class="td">{{ item[detailData.lastColField] | filterForamtThousand }}</div>
        </div>
      </template>
      <div v-if="dataList.length===0" class="no-data">{{ loadOver?'暂无数据':'加载中' }}</div>
    </div>
  </div>
</template>

<script>
import { parseTime } from '@/utils'
import { getLogisticsCoreCarDetail, getLogisticsOfficeCoreCarDetail,
  getLogisticsCoreArriveDetail, getLogisticsOfficeCoreArriveDetail,
  getLogisticsCoreShipContractDetail, getLogisticsOfficeCoreShipContractDetail } from '@/apis/logistics'
export default {
  name: 'LogisticsCoreDetail',
  props: {
    detailType: {
      type: String,
      default: ''
    },
    selectDate: {
      type: String,
      default: parseTime(new Date(), '{y}-{m}-{d}')
    },
    officeName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      detail: [
        { type: 'car', title: '配车(车)', lastColName: '待配车', lastColField: 'waitCareQuantity', today: 'todayCareQuantity', yesterday: 'yesterdayCareQuantity', month: 'monthCareQuantity' },
        { type: 'arrive', title: '到车(车)', lastColName: '计划到车', lastColField: 'planArriveQuantity', today: 'todayArriveQuantity', yesterday: 'yesterdayArriveQuantity', month: 'monthArriveQuantity' },
        { type: 'ship', title: '启运合同(车)', lastColName: '未启运', lastColField: 'notShipcontractQuantity', today: 'todayShipcontractQuantity', yesterday: 'yesterdayShipcontractQuantity', month: 'monthShipcontractQuantity' },
        { type: 'practical', title: '启运实际(车)', lastColName: '未启运', lastColField: 'practical' }
      ],
      tabIndex: 0,
      tabDisName: ['羊马', '潜江', '清丰'],
      coreDetailData: [],
      loadOver: false // 是否加载完成
    }
  },
  computed: {
    detailData() {
      const obj = this.detail.find(v => v.type === this.detailType)
      return obj || ''
    },
    dataList() {
      const disName = this.tabDisName[this.tabIndex]
      return this.coreDetailData.filter(v => v.deliveryCenter.indexOf(disName) > -1)
    }
  },
  created() {
    this.loadOver = false
    if (this.officeName) {
      this.getOfficeDetailData()
    } else {
      this.getDetailData()
    }
  },
  methods: {
    // 核心指标详情数据
    getDetailData() {
      if (this.detailType === 'car') {
      // 配车
        getLogisticsCoreCarDetail(this.selectDate).then(res => {
          this.coreDetailData = res.data || []
          this.loadOver = true
        }).catch(() => {
          this.loadOver = true
        })
      }
      if (this.detailType === 'arrive') {
      // 到车
        getLogisticsCoreArriveDetail(this.selectDate).then(res => {
          this.coreDetailData = res.data || []
          this.loadOver = true
        }).catch(() => {
          this.loadOver = true
        })
      }
      if (this.detailType === 'ship') {
      // 启运合同
        getLogisticsCoreShipContractDetail(this.selectDate).then(res => {
          this.coreDetailData = res.data || []
          this.loadOver = true
        }).catch(() => {
          this.loadOver = true
        })
      }
    },
    // 办事处核心指标详情
    getOfficeDetailData() {
      const param = {
        date: this.selectDate,
        officeName: this.officeName
      }
      if (this.detailType === 'car') {
      // 配车
        getLogisticsOfficeCoreCarDetail(param).then(res => {
          this.coreDetailData = res.data || []
          this.loadOver = true
        }).catch(() => {
          this.loadOver = true
        })
      }

      if (this.detailType === 'arrive') {
      // 到车
        getLogisticsOfficeCoreArriveDetail(param).then(res => {
          this.coreDetailData = res.data || []
          this.loadOver = true
        }).catch(() => {
          this.loadOver = true
        })
      }

      if (this.detailType === 'ship') {
      // 启运合同
        getLogisticsOfficeCoreShipContractDetail(param).then(res => {
          this.coreDetailData = res.data || []
          this.loadOver = true
        }).catch(() => {
          this.loadOver = true
        })
      }
    }
  }
}
</script>
<style lang='less' scoped>
  .dlg-title{
    // margin-bottom: 10px;
    padding:10px 0;
    line-height: 22px;
    border-bottom: 1px solid #F4F6F5;
    color: #333;
    font-size: 16px;
    letter-spacing: 1px;
    text-align: center;
    font-family: 'PFZH';
  }
  .dlg-tab{
    width: 100%;
    height: 32px;
    background: #F5F6F7;
    display: flex;
    margin-bottom: 10px;
    .tab-item{
      width: 33.33333%;
      height: 32px;
      line-height: 32px;
      font-size: 14px;
      font-family: PFZH;
      color: #888888;
      letter-spacing: 1px;
      text-align: center;
      &.active{
        color: #12B9A3;
        background: #FFFFFF;
        box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.1);
      }
    }
  }
  .core-detail-list{
    padding: 0 5px;
    font-size: 14px;
    text-align: center;
    min-height: 102px;
    .tr{
      min-height: 24px;
      margin-bottom: 10px;
      display: flex;
      align-items: center;
      color: #333333;
      letter-spacing: 1px;
    }
    .th,.td{
      width: 33.33333%;
      overflow: hidden;
    }
    .th{
      font-family: 'PFZH';
    }
  }
</style>
